angular.module('elife.services')
  .factory('popupService', function($rootScope,$ionicPopup) {
    // Might use a resource here that returns a JSON array
    function CustomPopup(popup){
      return {
        popup:popup,
        close:function(){
          $rootScope.dialogs.pop();
          this.popup.close();
        }
      };
    }
    return {
      show:function(popup){
        var pop = new CustomPopup($ionicPopup.show(popup))
        $rootScope.dialogs.push(pop);
        return pop;
      },
      alert:function(popup){
        var pop = new CustomPopup($ionicPopup.alert(popup))
        $rootScope.dialogs.push(pop);
        return pop;
      },
      confirm:function(popup){
        var pop = new CustomPopup($ionicPopup.confirm(popup))
        $rootScope.dialogs.push(pop);
        return pop;
      },
      prompt:function(popup){
        var pop = new CustomPopup($ionicPopup.prompt(popup))
        $rootScope.dialogs.push(pop);
        return pop;
      },
    };
  });
